var t = new (require("../../../utils/http").HTTP);
Page({
  data: {
    detail: [],
    yuding: "单房预定",
    yichuzu: !1,
    rent: !0,
    arr: [],
    beforeColor: "skyblue", //指示点颜色 
    afterColor: "#fff", //当前选中的指示点颜色 
    previousmargin: '24px', //前边距
    nextmargin: '24px', //后边距
    indicator: false, //是否显示指示点
    interval: 5000, //自动切换时间间隔
    duration: 500, //滑动动画时长
    autoplay: true, //是否自动切换
    circular: true, //是否采用衔接滑动
    cur: 0, //当前所在滑块的index
  },
  //轮播图的切换事件  
  swiperChange(e) {
    let cur = e.detail.current //获取当前轮播图片的下标, 可以给当前指示点加样式
    this.setData({
      cur: cur
    })
  },
  getParams: function () {
    var t = this;
    wx.request({
      url: "https://www.qlsyyun.com:3030/getParams",
      success: function (e) {
        t.setData({
          ossSignature: e.data.signature,
          ossAccessKeyId: e.data.OSSAccessKeyId,
          ossPolicy: e.data.policy
        })
      },
      fail: function (t) {
        console.log("请求签名失败：", t)
      }
    })
  },
  // 选择图片
  selectImage() {
    let that = this
    if ((that.data.user[2] == 101 || that.data.user[2] == 102 || that.data.user[3] == 1 || that.data.user[4] >= 6) && (that.data.detail.zt == that.data.user[1] || that.data.user[7].split(',').indexOf(that.data.detail.zt) !== -1)) {
      wx.chooseMedia({
        count: 1,
        mediaType: ['image'],
        sourceType: ['album', 'camera'],
        maxDuration: 30,
        camera: 'back',
        success(res) {
          const now = new Date();
          const year = now.getFullYear();
          const month = (now.getMonth() + 1).toString().padStart(2, '0');
          const day = now.getDate().toString().padStart(2, '0');
          const hours = now.getHours().toString().padStart(2, '0');
          const minutes = now.getMinutes().toString().padStart(2, '0');
          const seconds = now.getSeconds().toString().padStart(2, '0');
          let num = `${year}${month}${day}${hours}${minutes}-` + (Math.floor(Math.random() * 90) + 10) + '.jpg';
          wx.showLoading({
            title: '上传中',
          })
          wx.uploadFile({
            url: "https://qlsy.oss-cn-hangzhou.aliyuncs.com",
            filePath: res.tempFiles[0].tempFilePath,
            name: "file",
            formData: {
              key: 'fyzp/phone/' + num,
              policy: that.data.ossPolicy,
              OSSAccessKeyId: that.data.ossAccessKeyId,
              signature: that.data.ossSignature
            },
            success: function (e) {

              t.request({
                url: 'https://www.qlsyyun.com:3030/update/houseImage',
                method: 'POST',
                header: {
                  "Content-Type": "application/x-www-form-urlencoded"
                },
                data: {
                  hid: that.data.goodsId,
                  mc:that.data.detail.zt + that.data.detail.fjh,
                  FileUrl: num,
                  khbh: that.data.detail.fjbh,
                  tname: that.data.user[0],
                  AddTime: `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
                },
                success() {
                  wx.hideLoading({
                    title: "上传失败，请稍后重试",
                    icon: "loading",
                    mask: !0
                  })
                },
              })

            },
            fail: function (t) {
              wx.showLoading({
                title: "上传失败，请稍后重试",
                icon: "loading",
                mask: !0
              })
            },
            complete: function () {
              wx.hideLoading()
            }
          })
        }
      })
    } else {
      return wx.showToast({
        title: '请联系该项目运营',
        icon: 'none'
      })
    }
  },
  onLoad: function (a) {
    var e = this,
      i = wx.getStorageSync("user");
    e.getParams()
    e.setData({
      goodsId: a.goodsId,
      user: i
    });
    var o = [];
    o.push(a.goodsId),
      wx.setStorageSync("goodcid", o),
      t.request({
        url: "https://www.qlsyyun.com:3030/kongfang",
        data: {
          id: a.goodsId
        }
      }).then((function (t) {
        console.log(t.data[0])
        e.setData({
          detail: t.data[0]
        }),
          "已出租" == e.data.detail.czzk ? e.setData({
            yichuzu: !0,
            yuding: "单房续租"
          }) : e.setData({
            yichuzu: !1
          }),
          wx.setStorageSync("redact", e.data.detail)
        wx.request({
          url: `https://www.qlsyyun.com:3000/newPages/houseDetail/images?ycID=${a.goodsId}`,
          method: "GET",
          success(res) {
            e.setData({
              arr: res.data.data
            })
          },
        })
      }))
  },
  test: function () {
    let that = this
    if ((that.data.user[2] == 101 || that.data.user[2] == 102 || that.data.user[3] == 1 || that.data.user[4] >= 6) && (that.data.detail.zt == that.data.user[1] || that.data.user[7].split(',').indexOf(that.data.detail.zt) !== -1)) {
      wx.navigateTo({
        url: "../renew/renew"
      })
    } else {
      wx.showToast({
        title: "请联系该项目运营人员",
        icon: "none",
        duration: 1e3
      })
    }
  },
  test2: function () {
    "已预定" == this.data.yuding ? wx.showToast({
      title: "该房源已被预定",
      icon: "none",
      duration: 1e3
    }) : 101 == this.data.user[2] && this.data.guishu == this.data.detail.zt ? (wx.setStorageSync("redact", this.data.detail), wx.navigateTo({
      url: "../destined/destined"
    })) : wx.showToast({
      title: "请联系该项目运营人员",
      icon: "none",
      duration: 1e3
    })
  },
  yutuizu: function () {
    101 == this.data.user[2] ? wx.navigateTo({
      url: "../operate/throw/throw"
    }) : wx.showToast({
      title: "请联系该项目运营人员",
      icon: "none",
      duration: 1e3
    })
  },
  tuizu: function () {
    101 == this.data.user[2] ? wx.navigateTo({
      url: "../operate/surrender/surrender"
    }) : wx.showToast({
      title: "请联系该项目运营人员",
      icon: "none",
      duration: 1e3
    })
  }
});